<%@ page language="java" pageEncoding="UTF-8" import="com.chinapost.util.AuthUtil"%>
<%@ taglib prefix="my" uri="/WEB-INF/tlds/permission.tld" %>
<%
	AuthUtil authUtil = new AuthUtil(session);
%>
<script type="text/javascript">
var tqsj_datagrid;
$(function ()
{
    tqsj_datagrid = $('#tqsj_manager_datagrid').datagrid(
        {
            url : '${pageContext.request.contextPath}/tqsjAction!datagrid.action',
            pagination : true,
            pageSize : 20,
            pageList :  [  10, 20, 30, 40, 50 ],
            border : false,
            fit: true,
            fitColumns: true,
            idField : 'cid',
            sortName : 'cbh',
            sortOrder : 'asc',
            checkOnSelect : false,
            selectOnCheck : true,
            columns : [[
                    {
                        title : 'id',
                        field : 'cid',
                        width : 100,
                        align : "center",
                        checkbox:true
                    },
                    {
                        title : '部门名称',
                        field : 'deptname',
                        align : "center",
                        width : 120
                    },
                    {
                        title : '用户编号',
                        field : 'cbh',
                        align : "center",
                        width : 80
                    },
                    {
                        title : '用户名',
                        field : 'username',
                        align : "center",
                        width : 80
                    },
                    {
                        title : '上报月份',
                        field : 'csbyf',
                        align : "center",
                        width : 60
                    },
                    {
                        title : '业务类别',
                        field : 'kindname',
                        align : "center",
                        width : 80
                    },
                    {
                        title : '账号',
                        field : 'czh',
                        align : "center",
                        width : 100
                    },
                    {
                        title : '卡号（一本通）',
                        field : 'ckh',
                        align : "center",
                        width : 120
                    },
                    {
                        title : '开户局',
                        field : 'ckhj',
                        align : "center",
                        width : 70
                    },
                    {
                        title : '原余额',
                        field : 'cye',
                        align : "center",
                        width : 80
                    },
                    {
                        title : '存期',
                        field : 'ccq',
                        align : "center",
                        width : 50
                    },
                    {
                        title : '提前支取日期',
                        field : 'ctqrq',
                        align : "center",
                        width : 100
                    },
                    {
                        title : '提前支取金额',
                        field : 'ctqje',
                        align : "center",
                        width : 100
                    },
                    {
                        title : '提前支取积分',
                        field : 'ctqjf',
                        align : "center",
                        width : 100
                    },
                    {
                        title : '应扣奖励',
                        field : 'ctqfy',
                        align : "center",
                        width : 80
                    },
                    {
                        title : '状态',
                        field : 'czt',
                        align : "center",
                        width : 80
                    },
                    {
                        title : '备注',
                        field : 'cbz',
                        align : "center",
                        width : 80
                    }
                ]]
        }
        );
	$('#tqsj_jstqzq_deptid').combotree({
		lines : true,
		url : 'deptAction!do_combotree.action',
		panelHeight : 260,
		required : true,
		editable : false,
		idField : 'id',
		textField : 'text',
		parentField : 'pid',
		onBeforeSelect : function(node) {
			if ($(this).tree('isLeaf', node.target)) {
				return false;
			}
		},
		onClick : function(node) {
			if ($(this).tree('isLeaf', node.target)) {
				$('#tqsj_jstqzq_deptid').combo('showPanel');
			}
		}
	});
	$('#tqsj_jstqzq_deptid').combotree('setValue', '${sessionInfo.deptid}');
    $('#tqsj_manager_dept').val('${sessionInfo.deptid}');
}
);


function _searchTqsj() {
	tqsj_datagrid.datagrid('load', sy.serializeObject($('#tqsj_search_form')));
	tqsj_datagrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
};
function _cleanSearchTqsj() {
	$('#tqsj_search_form  input').val('');
	$('#tqsj_manager_dept').combotree('setValue','${sessionInfo.deptid}');
	tqsj_datagrid.datagrid('load', sy.serializeObject($('#tqsj_search_form')));
	 $('#tqsj_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
};

function _getTqzqsj(){
	var sbyf = $('#tqsj_manager_csbyf').val();
	if (sbyf.length >0 ){
		 $.ajax(//先判断基础数据是否存在，否则不计算提前支取
                 {
                     url : '${pageContext.request.contextPath}/monthAction!do_checkMonth.action',
                     data :
                     {
                         cmonth:sbyf,
                         cid:1
                     },
                     async:false,
                     dataType : 'json',
                     cache : false,
                     success : function (d)
                     {
                    	 if (d.success){
                    		 parent.sy.messagerAlert('提示', '本月定期基础数据还未导入，请先导入基础数据！', 'error');
                    	 }else{
                    		 _jsTqzqsj();
                    	 };
                     }
                 }
                 );

	}else{
		parent.sy.messagerAlert('提示', '请选择要计算的月份！', 'error');
	}
}

function _jsTqzqsj(){
	$.messager.progress({
		text : '正在计算，请稍候...',
		interval : 100
	});
	$.post("tqsjAction!addTqsjs.action", {
		deptid : $('#tqsj_jstqzq_deptid').combotree('getValue'),
		createuserid : '${sessionInfo.userId}' ,
		csbyf : $('#tqsj_manager_csbyf').val()
	}, function(rsp) {
		if (rsp.success) {
			tqsj_datagrid.datagrid('reload');
		}
		$.messager.progress('close');
		parent.sy.messagerAlert('提示', rsp.msg, 'info');
	}, "JSON");
}

function export_tqsj() {
	var smonth=$('#tqsj_startMonth').val();
	var emonth=$('#tqsj_endMonth').val();
	if (smonth.length >0 && emonth.length >0){
	 url='${pageContext.request.contextPath}/tqsjAction!exportExcel.action';
	 $('#tqsj_search_form').attr('action',url);
     $('#tqsj_search_form').submit();
	}else{
		parent.sy.messagerAlert('提示', '请选择要导出数据的起始月份和结束月份！', 'error');
	}
}
</script>

<div class="easyui-layout" data-options="fit:true" style="overflow: hidden;">
	<div data-options="region:'north',title:'查询',iconCls:'icon-search'" style="height: 135px;padding:5px;overflow: hidden;">
		<div style="padding:10px 5px">
		<span>选择单位：</span><input type="text" id="tqsj_jstqzq_deptid" />&nbsp;
		<span>选择月份：</span><input type="text" id="tqsj_manager_csbyf" class="easyui-my97" name="csbyf" data-options="dateFmt:'yyyyMM'"  style="width:120px"/>&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-hamburg-pencil'" onclick="_getTqzqsj();">计算提前支取</a>
		</div>
		<div style="padding:10px 5px ;border-top: 1px dotted #aed0ea">
			<form method="post" id="tqsj_search_form" style="display:inline">
			<span>所属单位：</span>
			<input id="tqsj_manager_dept" class="easyui-combotree" name="deptid" data-options="lines:true,url:'deptAction!do_combotree.action',panelHeight:280,required:true,editable:false,idField:'id',textField:'text',parentField:'pid'" style="width:150px"/>&nbsp;
			<span>人员编号：</span>
			<input type='text' id="tqsj_manager_userbh" name='cbh' style="width:80px" />&nbsp;
			<span>账号：</span>
			<input type='text' name='czh'  style="width:80px"/>&nbsp;
			<span>开始月份：</span>
			<input class="easyui-my97" type="text" id="tqsj_startMonth" name="startMonth"  data-options="dateFmt:'yyyyMM'" style="width:80px"/>&nbsp;
			<span>结束月份：</span>
			<input class="easyui-my97" type="text" id="tqsj_endMonth" name="endMonth"  data-options="dateFmt:'yyyyMM'" style="width:80px"/>&nbsp;
			</form>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="_searchTqsj();">查询</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onClick="_cleanSearchTqsj();;">清空</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-excel'" onClick="export_tqsj();;">导出</a>
		</div>
	</div>
	<div data-options="region:'center',title:'提前支取数据列表',border:true,iconCls:'icon-menu'" style="overflow: hidden;">
		<table id="tqsj_manager_datagrid"></table>
	</div>
</div>
